<template>
    <div>
      <div class="opt-area-02">
        <div class="right-con">
          <div class="input-frame" style="width: 164px">
            <Select v-model="user_type">
              <Option value="">全部</Option>
              <Option value="1">社区</Option>
              <Option value="2">村</Option>
            </Select>
          </div>
          <Button type="info" size="small" @click="init" style="margin-top: 5px">搜索</Button>
        </div>
      </div>
      <div>
        <div style="text-align: right">时间：{{nowDate}}</div>
        <template>
          <Table v-if="tableShow" :columns="columns" :data="data" border :loading="tableLoading"></Table>
        </template>
      </div>
    </div>
</template>

<script>
import { findTableNumNewList, findTableNumOldList } from '../../../api/yi-qing-fang-kong'

export default {
  name: 'index',
  data () {
    return {
      user_type: '',
      columns: [
        {
          title: '序号',
          type: 'index',
          align: 'center',
          fixed: 'left',
          width: 50
        },
        {
          title: '区县',
          key: 'city',
          align: 'center',
          fixed: 'left',
          width: 100
        },
        {
          title: '来（返）乡人员情况',
          align: 'center',
          children: [
            {
              title: '来自国内中高风险地区人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'zhonggaofengxiannumold',
                  align: 'center',
                  width: 100
                },
                {
                  title: '实有',
                  key: 'zhonggaofengxiannum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '境外人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'jingwainumold',
                  align: 'center',
                  width: 100
                },
                {
                  title: '实有',
                  key: 'jingwainum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '从事冷链食品相关工作返乡人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'lengliannumold',
                  align: 'center',
                  width: 100
                },
                {
                  title: '实有',
                  key: 'lengliannum',
                  align: 'center',
                  width: 100
                }
              ]
            }
          ]
        },
        {
          title: '管控人员情况',
          align: 'center',
          width: 200,
          children: [
            {
              title: '居家隔离人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'jujiagelinumOld',
                  align: 'center',
                  width: 100
                },
                {
                  title: '现有',
                  key: 'jujiagelinum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '健康检测人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'jiankangjiancenumOld',
                  align: 'center',
                  width: 100
                },
                {
                  title: '现有',
                  key: 'jiankangjiancenum',
                  align: 'center',
                  width: 100
                }
              ]
            }
          ]
        },
        {
          title: '密切接触人员情况',
          align: 'center',
          children: [
            {
              title: '一密解除人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'yijimijienum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '二密解除人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'erjimijienum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '三密解除人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'sanjimijienum',
                  align: 'center',
                  width: 100
                }
              ]
            }
          ]
        },
        {
          title: '离沈人员数',
          width: 200,
          align: 'center',
          children: [
            {
              title: '累计',
              key: 'lishennum',
              align: 'center',
              width: 100
            }
          ]
        }
      ],
      columns1: [
        {
          title: '序号',
          type: 'index',
          align: 'center',
          fixed: 'left',
          width: 50
        },
        {
          title: '区县',
          key: 'city',
          align: 'center',
          fixed: 'left',
          width: 100
        },
        {
          title: '来（返）乡人员情况',
          align: 'center',
          children: [
            {
              title: '来自国内中高风险地区人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'zhonggaofengxiannumold',
                  align: 'center',
                  width: 100
                },
                {
                  title: '实有',
                  key: 'zhonggaofengxiannum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '境外人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'jingwainumold',
                  align: 'center',
                  width: 100
                },
                {
                  title: '实有',
                  key: 'jingwainum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '从事冷链食品相关工作返乡人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'lengliannumold',
                  align: 'center',
                  width: 100
                },
                {
                  title: '实有',
                  key: 'lengliannum',
                  align: 'center',
                  width: 100
                }
              ]
            }
          ]
        },
        {
          title: '管控人员情况',
          align: 'center',
          width: 200,
          children: [
            {
              title: '居家隔离人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'jujiagelinumOld',
                  align: 'center',
                  width: 100
                },
                {
                  title: '现有',
                  key: 'jujiagelinum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '健康监测人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'jiankangjiancenumOld',
                  align: 'center',
                  width: 100
                },
                {
                  title: '现有',
                  key: 'jiankangjiancenum',
                  align: 'center',
                  width: 100
                }
              ]
            }
          ]
        },
        {
          title: '密切接触人员情况',
          align: 'center',
          children: [
            {
              title: '一密解除人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'yijimijienum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '二密解除人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'erjimijienum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '三密解除人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'sanjimijienum',
                  align: 'center',
                  width: 100
                }
              ]
            }
          ]
        },
        {
          title: '离沈人员数',
          width: 200,
          align: 'center',
          children: [
            {
              title: '累计',
              key: 'lishennum',
              align: 'center',
              width: 100
            }
          ]
        }
      ],
      columns2: [
        {
          title: '序号',
          type: 'index',
          align: 'center',
          fixed: 'left',
          width: 50
        },
        {
          title: '区县',
          key: 'city',
          align: 'center',
          fixed: 'left',
          width: 100
        },
        {
          title: '来（返）乡人员情况',
          align: 'center',
          children: [
            {
              title: '来（返）乡人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'laifanxiangnumOld',
                  align: 'center',
                  width: 80
                },
                {
                  title: '实有',
                  key: 'laifanxiangnum',
                  align: 'center',
                  width: 80
                }
              ]
            },
            {
              title: '来自国内中高风险地区人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'zhonggaofengxiannumold',
                  align: 'center',
                  width: 80
                },
                {
                  title: '实有',
                  key: 'zhonggaofengxiannum',
                  align: 'center',
                  width: 80
                }
              ]
            },
            {
              title: '境外人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'jingwainumold',
                  align: 'center',
                  width: 80
                },
                {
                  title: '实有',
                  key: 'jingwainum',
                  align: 'center',
                  width: 80
                }
              ]
            },
            {
              title: '从事冷链食品相关工作返乡人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'lengliannumold',
                  align: 'center',
                  width: 80
                },
                {
                  title: '实有',
                  key: 'lengliannum',
                  align: 'center',
                  width: 80
                }
              ]
            }
            // {
            //   title: '是否存在发热人员等潜在风险因素',
            //   align: 'center',
            //   width: 200
            // }
          ]
        },
        {
          title: '管控人员情况',
          align: 'center',
          width: 200,
          children: [
            {
              title: '居家隔离人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'jujiagelinumOld',
                  align: 'center',
                  width: 100
                },
                {
                  title: '现有',
                  key: 'jujiagelinum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '健康检测人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'jiankangjiancenumOld',
                  align: 'center',
                  width: 100
                },
                {
                  title: '现有',
                  key: 'jiankangjiancenum',
                  align: 'center',
                  width: 100
                }
              ]
            }
          ]
        },
        {
          title: '密切接触人员情况',
          align: 'center',
          children: [
            {
              title: '一密解除人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'yijimijienum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '二密解除人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'erjimijienum',
                  align: 'center',
                  width: 100
                }
              ]
            },
            {
              title: '三密解除人员数',
              align: 'center',
              children: [
                {
                  title: '累计',
                  key: 'sanjimijienum',
                  align: 'center',
                  width: 100
                }
              ]
            }
          ]
        },
        {
          title: '离沈人员数',
          width: 200,
          align: 'center',
          children: [
            {
              title: '累计',
              key: 'lishennum',
              align: 'center',
              width: 100
            }
          ]
        }
      ],
      data: [],
      nowDate: this.time(new Date()),
      tableLoading: false,
      tableShow: true
    }
  },
  methods: {
    init () {
      this.findTableNumNewList()
    },
    async findTableNumNewList () {
      this.tableLoading = true
      let params = {
        user_type: this.user_type
      }
      await findTableNumNewList(params).then(ret => {
        if (ret.data.errcode === 0) {
          let data = ret.data.data
          this.findTableNumOldList(data)
        } else {
          this.$Notice.error({ title: '修改失败', desc: ret.data.errmsg })
        }
      })
    },
    time (date) {
      var y = date.getFullYear()
      var m = date.getMonth() + 1
      m = m < 10 ? ('0' + m) : m
      var d = date.getDate()
      d = d < 10 ? ('0' + d) : d
      // var h = date.getHours()
      // h = h < 10 ? ('0' + h) : h
      // var minute = date.getMinutes()
      // minute = minute < 10 ? ('0' + minute) : minute
      // var second = date.getSeconds()
      // second = second < 10 ? ('0' + second) : second
      // return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second
      return y + '年' + m + '月' + d + '日'
    },
    findTableNumOldList (e) {
      let data1 = []
      let data2 = []
      let params = {
        user_type: this.user_type
      }
      findTableNumOldList(params).then(ret => {
        if (ret.data.errcode === 0) {
          data1 = e
          data2 = ret.data.data
          for (let i = 0; i < data1.length; i++) {
            for (let j = 0; j < data2.length; j++) {
              if (data1[i].city_code === data2[j].city_code) {
                data1[i].jujiagelinumOld = data2[j].jujiagelinumOld + data1[i].jujiagelinum
                data1[i].jiankangjiancenumOld = data2[j].jiankangjiancenumOld + data1[i].jiankangjiancenum
                data1[i].lengliannumold = data2[j].lengliannumold + data1[i].lengliannum
                data1[i].jingwainumold = data2[j].jingwainumold + data1[i].jingwainum
                data1[i].zhonggaofengxiannumold = data2[j].zhonggaofengxiannumold + data1[i].zhonggaofengxiannum
                data1[i].laifanxiangnumOld = data2[j].laifanxiangnumOld + data1[i].laifanxiangnum
              }
            }
          }
          this.data = data1
          let zhonggaofengxiannumold = 0
          let zhonggaofengxiannum = 0
          let jingwainumold = 0
          let jingwainum = 0
          let lengliannumold = 0
          let lengliannum = 0
          let jujiagelinumOld = 0
          let jujiagelinum = 0
          let jiankangjiancenumOld = 0
          let jiankangjiancenum = 0
          let yijimijienum = 0
          let erjimijienum = 0
          let sanjimijienum = 0
          let lishennum = 0
          let laifanxiangnum = 0
          let laifanxiangnumOld = 0
          this.data.forEach(item => {
            if (item.zhonggaofengxiannumold) {
              console.log(item.city)
              zhonggaofengxiannumold = zhonggaofengxiannumold + item.zhonggaofengxiannumold
            }
            if (item.jingwainumold) {
              jingwainumold = jingwainumold + item.jingwainumold
            }
            if (item.lengliannumold) {
              lengliannumold = lengliannumold + item.lengliannumold
            }
            if (item.jujiagelinumOld) {
              jujiagelinumOld = jujiagelinumOld + item.jujiagelinumOld
            }
            if (item.jiankangjiancenumOld) {
              jiankangjiancenumOld = jiankangjiancenumOld + item.jiankangjiancenumOld
            }
            if (item.laifanxiangnumOld) {
              laifanxiangnumOld = laifanxiangnumOld + item.laifanxiangnumOld
            }
            zhonggaofengxiannum = zhonggaofengxiannum + item.zhonggaofengxiannum
            jingwainum = jingwainum + item.jingwainum
            lengliannum = lengliannum + item.lengliannum
            jujiagelinum = jujiagelinum + item.jujiagelinum
            jiankangjiancenum = jiankangjiancenum + item.jiankangjiancenum
            yijimijienum = yijimijienum + item.yijimijienum
            erjimijienum = erjimijienum + item.erjimijienum
            sanjimijienum = sanjimijienum + item.sanjimijienum
            lishennum = lishennum + item.lishennum
            laifanxiangnum = laifanxiangnum + item.laifanxiangnum
          })
          this.data.push({
            city: '合计',
            zhonggaofengxiannumold: zhonggaofengxiannumold,
            zhonggaofengxiannum: zhonggaofengxiannum,
            jingwainumold: jingwainumold,
            jingwainum: jingwainum,
            lengliannumold: lengliannumold,
            lengliannum: lengliannum,
            jujiagelinumOld: jujiagelinumOld,
            jujiagelinum: jujiagelinum,
            jiankangjiancenumOld: jiankangjiancenumOld,
            jiankangjiancenum: jiankangjiancenum,
            yijimijienum: yijimijienum,
            erjimijienum: erjimijienum,
            sanjimijienum: sanjimijienum,
            lishennum: lishennum,
            laifanxiangnum: laifanxiangnum,
            laifanxiangnumOld: laifanxiangnumOld
          })
          this.tableLoading = false
          console.log(this.user_type)
          if (this.user_type === '' || this.user_type === undefined) {
            this.columns = []
            this.columns = this.columns1
            this.tableShow = false
            this.$nextTick(() => {
              this.tableShow = true
            })
          }
          if (this.user_type === '1') {
            this.columns = []
            this.columns = this.columns1
            this.tableShow = false
            this.$nextTick(() => {
              this.tableShow = true
            })
          }
          if (this.user_type === '2') {
            this.columns = []
            this.columns = this.columns2
            this.tableShow = false
            this.$nextTick(() => {
              this.tableShow = true
            })
          }
        } else {
          this.$Notice.error({ title: '修改失败', desc: ret.data.errmsg })
        }
      }).catch(err => {
        console.log(err)
      })
    }
  },
  mounted () {
    this.init()
  }
  // watch: {
  //   user_type (e) {
  //     console.log('user_type', e)
  //     if (e === '') {
  //       this.columns = this.columns1
  //       this.tableShow = false
  //       this.$nextTick(() => {
  //         this.tableShow = true
  //       })
  //     }
  //     if (e === 1) {
  //       this.columns = this.columns1
  //       this.tableShow = false
  //       this.$nextTick(() => {
  //         this.tableShow = true
  //       })
  //     }
  //     if (e === 2) {
  //       this.columns = this.columns2
  //       this.tableShow = false
  //       this.$nextTick(() => {
  //         this.tableShow = true
  //       })
  //     }
  //   }
  // }
}
</script>

<style scoped>
  .opt-area-02 {
    display: flex;
    align-items: center;
    flex-direction: column;
    border: 1px solid #abdcff;
    background-color: #f0faff;
    padding: 8px 16px 8px 16px;
    border-radius: 4px;
    margin-bottom: 10px;
  }

  .opt-area-02 .right-con {
    width: 100%;
    margin-top: 5px;
    display: flex;
  }

  .opt-area-02 .left-con {
    font-size: 14px;
    width: 100%;
  }

  .opt-area-02 .left-con span {
    font-weight: bold;
  }

  .opt-area-02 .right-con input {
    width: 150px;
    margin-right: 10px;
  }

  .opt-area-02 .right-con .input-frame {
    width: 200px;
    margin-right: 10px;
  }
</style>
